<!-- 回车登记 -->
<template>
  <div
    class="dashboard-container dispatch-task customer-list-box"
    style="width: 100%">
    <div class="app-container">
      <el-card
        class="search-card-box"
        shadow="never">
        <el-form
          ref="truckFormData"
          :model="truckFormData"
          label-width="80px">
          <div class="filter-container">
            <el-row
              :gutter="60"
              class="nvaheiht">
              <el-col :span="8">
                <el-form-item
                  label="车辆类型:"
                  style="margin-bottom: 0px;margin-top: 5px"
                  label-width="110px">
                  <treeselect
                    v-model="truckFormData.startAgencyId"
                    :options="agencyOptions"
                    :normalizer="normalizer"
                    :searchable="true"
                    style="width: 100%"
                    placeholder="请选择"
                    no-options-text="暂无数据"
                    no-results-text="暂无数据" />
                  <img
                    ref="arrow"
                    src="@/assets/pullDown.png"
                    style="
                      position: absolute;
                      width: 18px;
                      height: 18px;
                      right: 9px;
                      top: 12px;
                      cursor: pointer;
                      pointer-events: none;
                      transition-duration: 0.3s;
                    " />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  label="车牌号码:"
                  style="margin-bottom: 0px;margin-top: 5px"
                  label-width="110px">
                  <el-input
                    v-model="truckFormData.transportTaskId"
                    placeholder="请输入号码"
                    clearable />
                </el-form-item>
              </el-col>

              <el-col
                :span="8"
                style="margin-bottom: 0px;margin-top: 5px">
                <el-button
                  type="warning"
                  @click="handleFilter('查询')">搜索</el-button>
                <el-button
                  class="reset-btn"
                  plain
                  @click="resetForm('truckFormData')">重置</el-button>
              </el-col>
            </el-row>
          </div>
        </el-form>
      </el-card>
      <TabChange
        :default-active-index="0"
        :is-show-num="true"
        :setting-list="[
          {
            value: 0,
            label: '全部',
            num: total
          },
          {
            value: 1,
            label: '可用',
            num: usable
          },
          {
            value: 2,
            label: '停用',
            num: block
          },

        ]"
        @tabChange="tabChange"></TabChange>
      <div
        v-loading="listLoading"
        :class="{ 'loading-box': listLoading }"
        element-loading-text="加载中"
        style="margin-top: 20px">
        <el-card
          class="table-card-box"
          shadow="never">
          <el-table
            :key="tableKey"
            ref="multipleTable"
            :data="dataList"
            fit
            style="width: 100%"
            stripe
            :header-cell-style="{ background: 'rgba(250,252,255,1)' }"
            @selection-change="handleSelectionChange">
            <div
              v-show="
                (!dataList || dataList.length <= 0) &&
                  !listLoading &&
                  !searchkey
              "
              slot="empty">
              <img
                src="@/icons/pic-kong.png"
                alt="img"
                style="margin-top: 20px; width: 25%; height: 25%" />
              <p style="margin-top: -20px; padding-bottom: 0px">这里空空如也</p>
            </div>
            <!-- <el-card
              v-show="
                (!dataList || dataList.length <= 0) && !listLoading && searchkey
              "
              slot="empty"
              class="table-empty-box"
              shadow="never"
            >
              <empty></empty>
            </el-card> -->
            <el-table-column
              align="left"
              label="序号"
              width="70px"
              type="index">
            </el-table-column>
            <el-table-column
              align="left"
              label="车牌号码"
              min-width="180"
              prop="licensePlate">
            </el-table-column>
            <el-table-column
              align="left"
              label="车辆类型"
              min-width="180"
              prop="truckTypeName">
            </el-table-column>
            <el-table-column
              align="left"
              label="司机数量"
              min-width="120"
              prop="driverNum">
            </el-table-column>

            <el-table-column
              align="left"
              label="车辆状态"
              min-width="160"
              prop="status">
              <template slot-scope="scope">
                <div
                  class="tableColumn-status"
                  :class="{ 'stop-use': !scope.row.workStatus }">
                  {{ scope.row.workStatus ? '可用' : '停用' }}
                </div>
              </template>
            </el-table-column>
            <el-table-column
              align="left"
              label="GPS设备ID"
              min-width="160"
              prop="deviceGpsId">
            </el-table-column>
            <el-table-column
              align="left"
              label="实载数量（T）"
              min-width="160"
              prop="allowableLoad">
            </el-table-column>
            <el-table-column
              align="left"
              label="实载体积（方）"
              min-width="120px"
              prop="allowableVolume">
            </el-table-column>
            <!-- 操作按钮 -->
            <el-table-column
              width="220px"
              align="center"
              label="操作"
              fixed="right"
              class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-link
                  type="primary"
                  :underline="false"
                  @click="handleAddLine(scope.row.id)">查看详情</el-link>
                <el-divider direction="vertical"></el-divider>
                <el-link
                  type="primary"
                  :underline="false"
                  @click="handleDeleteLine(scope.row.id)">启用</el-link>
                <el-divider direction="vertical"></el-divider>
                <el-link
                  type="primary"
                  :underline="false"
                  @click="handleAddTrips(scope.row.id, scope.row.name)">配置司机</el-link>
              </template>
            </el-table-column>

          </el-table>
          <!-- end -->
          <!-- 分页 -->
          <div
            v-if="total > 10"
            class="pagination">
            <div class="pages">
              <el-pagination
                :current-page="Number(truckFormData.page)"
                :total="Number(total)"
                :page-size="Number(truckFormData.pageSize)"
                :page-sizes="[10, 20, 30, 50]"
                layout="total, sizes, prev, pager, next, jumper"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange" />
            </div>
          </div>
        </el-card>
      </div>
    </div>
  </div>
</template>

<script>

import { truckList, getCarTypeStatics } from '@/api/transit'

import TabChange from '@/components/TabChange'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import Treeselect from '@riophae/vue-treeselect'
import { agencyList } from '@/api/institutions'

export default {
  components: {
    Treeselect, TabChange
  },
  data() {
    return {
      usable: '',
      block: '',
      carTypeStatics: {},
      tableKey: 0,
      dataList: [],
      total: null,
      searchkey: false,
      tableChecked: [],

      listLoading: true,
      truckFormData: {
        page: 1,
        pageSize: 10,
        transportTaskId: '',
        startAgencyId: null,
        endAgencyId: null,
        isAvailable: '',
        intoStorageStartTime: '',
        intoStorageEndTime: ''
      },
      intoStorage: [],
      agencyOptions: [],
      normalizer(node) {
        return {
          id: node.id,
          label: node.name,
          children: node.children
        }
      }
    }
  },
  // 挂载结束
  mounted: function () {},
  // 创建完毕状态
  async created() {
    this.getAgencyList()
    this.initialDate()
    // 键盘enter操作
    document.onkeydown = function (e) {
      var key = window.event.keyCode
      if (key === 13) {
        this.handleFilter(this.truckFormData)
      }
    }
  },
  // 组件更新
  updated: function () {},
  methods: {
    // 导航栏切换

    tabChange(val) {
      console.log('[  ] >', val)
    },
    // 获取起始/目的地机构列表数据
    async getAgencyList() {
      const { data: res } = await agencyList()
      // 获取数据给options
      this.agencyOptions = JSON.parse(res)
    },
    selectStartAgency(val) {
      this.truckFormData.startAgencyId = val.id
    },
    selectEndAgency(val) {
      this.truckFormData.endAgencyId = val.id
    },
    handleEstimatedTimeChange(val) {
      if (!val) {
        this.intoStorage = []
        this.truckFormData.intoStorageStartTime = ''
        this.truckFormData.intoStorageEndTime = ''
      } else {
        this.intoStorage = val
        this.truckFormData.intoStorageStartTime = val[0]
        this.truckFormData.intoStorageEndTime = val[1]
      }
    },
    // 初始数据
    initialDate() {
      // 读取数据
      this.getList()
    },

    handleSelectionChange(val) {
      this.tableChecked = val
    },
    // 获取列表数据
    async getList() {
      this.listLoading = true
      const Statics = await getCarTypeStatics()
      console.log('[ Statics ] >', Statics.data['0'])
      this.usable = Statics.data['1']
      this.block = Statics.data['0']
      const res = await truckList({
        page: this.truckFormData.page,
        pageSize: this.truckFormData.pageSize
      })
      console.log('[ res1111 ] >', res)

      this.listLoading = false
      // 获取数据给dataList
      this.dataList = res.data.items
      // 获取总条数
      this.total = res.data.counts
    },
    // 重置
    resetForm() {
      this.$refs['truckFormData'].resetFields()
      this.truckFormData.page = 1
      this.truckFormData.pageSize = 10
      this.truckFormData.transportTaskId = ''
      this.truckFormData.startAgencyId = ''
      this.truckFormData.endAgencyId = ''
      this.searchkey = false
      this.truckFormData.isAvailable = ''
      this.truckFormData.intoStorageStartTime = ''
      this.truckFormData.intoStorageEndTime = ''
      this.intoStorage = []
      this.getList()
    },
    // 搜索信息
    handleFilter() {
      this.getList()
      this.searchkey = true
    },
    // 每页显示信息条数
    handleSizeChange(val) {
      this.truckFormData.pageSize = val
      if (this.truckFormData.page === 1) {
        this.getList()
      }
    },
    // 进入某一页
    handleCurrentChange(val) {
      this.truckFormData.page = val
      this.getList()
    },

    // 查看回车登记详情
    handleWayllDetail(id) {
      this.$router.push({
        path: '/transit/car-register-info',
        query: { id: id }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.pagination {
  margin-top: 40px;
}
// 下拉框
::v-deep .el-select {
  width: 100%;
}
</style>

<style lang="scss" scoped>
::v-deep .el-card {
  overflow: initial;
}
::v-deep .vue-treeselect__menu-container {
  z-index: 9999 !important;
}
.nvaheiht {
 height: 50px;
}
</style>
